/***
  HiloMonitor.java is part of Marioneta.

  Marioneta is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License.

  Marioneta is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
  
  
  @author martin
   Martin Edmundo Barriga Orozco, 2008
   martin.barriga@gulmore.org
  
  HiloMonitor: Su funcion es recibir los eventos producidos por el moviento del
  mouse, como son muchos tener un thread nos ayuda a evitar la saturacion y darle
  holgura al Frame para que haga el repaint mas comodmente. 
 */

package escritorioremoto;

import java.awt.Image;
import java.awt.event.MouseEvent;
import java.io.IOException;

public class HiloMonitor extends Thread {
    gui_server boss;
    MouseEvent evento;
    
    public HiloMonitor(gui_server little_boss, MouseEvent ev){
        boss = little_boss;
        evento = ev;
    }
    
    @Override
    public void run(){
        if( boss.getMutex() ){
            boss.setMutex(false);
            Image aux;
            
            int x,y;
            if( boss.getOriginalSize() ){
                x = evento.getX()-boss.getInsets().left;
                y = evento.getY()-boss.getInsets().top;
            }
            else{
                x = (evento.getX()-boss.getInsets().left)*2;
                y = (evento.getY()-boss.getInsets().top)*2;
            }
            try{
                System.out.print("Enviando Commando...");
                boss.getIoServer().sendStr("%"+  x + ","+ y );
                aux = boss.getImgServer().getting_img();
                boss.setImgBackground(aux);
            }
            catch(IOException e){
                System.out.println("Error");
            }
            boss.setMutex(true);
        }
    }
}